package com.goosuncc.gscc.sdk;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.goosuncc.gscc.sdk.command.response.BindCustomerBatchLinkResponse;
import com.goosuncc.gscc.sdk.command.response.GetAgentReportResponse;
import com.goosuncc.gscc.sdk.command.response.GetAllUserAgentResponse;
import com.goosuncc.gscc.sdk.command.response.GetCustomerContactHistoryResponse;
import com.goosuncc.gscc.sdk.command.response.GetExtColumnResponse;
import com.goosuncc.gscc.sdk.command.response.HelloWorldResponse;
import com.goosuncc.gscc.sdk.command.response.ImportCustomerBatchResponse;
import com.goosuncc.gscc.sdk.command.response.ImportCustomerResponse;
import com.goosuncc.gscc.sdk.command.response.bean.CustomerBatch;
import com.goosuncc.gscc.sdk.command.response.bean.ViewCustomer;

/**
 * @version 2.0
 */
public class SampleCode {

    /**
     * 注意！！！！！！！！
     * 
     * gsccUrl 格式请参考 GSCC 2 API 文档
     */
    private static String gsccUrl = "http://192.168.8.227:18080/gscc/api/2.0";

    /**
     * 注意！！！！！！！！
     * 
     * apiSecret在gscc系统的API界面中配置。 即：启用apiSecret后的apiSecret
     */
    private static String apiSecret = "pA55w0rd";

    private static int connectTimeout = 5000;
    private static int readTimeout = 5000;

    // 初始化构造
    private static GsccServer gsccServer = new GsccServer(gsccUrl, apiSecret, connectTimeout, readTimeout);

    public static void main2(String[] args) {

    	/**
    	 * 测试demo
    	 */
    	HelloWorldResponse helloWorldResponse = gsccServer.helloWorldCommand();
        System.out.println(helloWorldResponse.toJsonString());
        
    }
    
    public static void main(String[] args) {
	}

    public static void main1(String[] args) {

    	/**
    	 * 测试demo
    	 */
    	HelloWorldResponse helloWorldResponse = gsccServer.helloWorldCommand();
        System.out.println(helloWorldResponse.toJsonString());
    	
    	/**
         * 获取用户坐席
         */
    	//用户编号
    	Long id = null;
    	//用户登录名
        String loginName = null;
        //用户工号
        Long jobNumber = null;
        //用户昵称
        String nickName = null;
        GetAllUserAgentResponse getAllUserAgentResponse = gsccServer.getAllUserAgentCommand(id,loginName,jobNumber,nickName);
        System.out.println(getAllUserAgentResponse.toJsonString());
    	
        /**
         *  获取客户沟通历史记录
         */
    	String customerPhoneNumber = "15712345678";//号码
    	Long startTime = System.currentTimeMillis();//开始时间
    	Integer limit = 10;//获取多少跟进记录
        GetCustomerContactHistoryResponse blacklistGetAllResponse = gsccServer.getCustomerContactHistory(customerPhoneNumber,startTime,limit);
        System.out.println(blacklistGetAllResponse.toJsonString());
        
        /**
         * 获取扩展字段
         */
        String tableName = "qqd_company";//可扩展的表名
        GetExtColumnResponse getExtColumnResponse = gsccServer.getExtColumn(tableName);
        System.out.println(getExtColumnResponse.toJsonString());
        
        /**
         * 获取座席话务报表
         */
        //坐席用户的UUID
        String agentAid = "admin";
        //坐席的昵称
        String agentName = "超级管理员";
        //报表类型：小时报【ByHour】日报【ByDay】月报【ByMONTH】年报【ByYEAR】
        String reportDuration = "ByDay";
        //报表排序方式：按座席排序【ByAgent】
        //按通次排序【OrderByBridgeCount】按通时排序【OrderByBridgeBillSecondsSum】按平均通时排序【OrderByBridgeBillSecondsAvg】
        //按未通次排序【OrderByUnBridgeCount】按未通时排序【OrderByUnBridgeDuraionSum】按平均未通时排序【OrderByUnBridgeDuraionAvg】
        String orderByType = "ByAgent";
        //开始时间
        String start_stamp = "2019-02-18 00:00:00";
        //结束时间
        String end_stamp = "2019-02-18 23:59:59";
        //是否展示完整数据，true展示所有数据包括去除全0数据。false不展示所有输出去除全0数据。
        Boolean showAllData = true;
        GetAgentReportResponse getAgentReportResponse = gsccServer.getAgentReportCommand(agentAid,agentName,reportDuration,orderByType,start_stamp,end_stamp,showAllData);
        System.out.println(getAgentReportResponse.toJsonString());

        /**
    	 * 导入客户
    	 */
        List<ViewCustomer> viewCustomerList = new ArrayList<>();
           //重新写入客户信息
        Boolean overWriteData = true;
        
        ViewCustomer viewCustomer = new ViewCustomer();
        //基本字段
        //电话,必填
        String phoneNumber = "15712345678";
        //邮箱
    	String email = "15712345678@qq.com";
    	//姓名
    	String name = "测试姓名";
    	//性别，0【女】 1【男】  2【未知】
    	String sex = "0";
    	//生日
    	String birthdayStr = "2019-02-20";
    	//国家
    	String countryName = "测试国家";
    	//省份
    	String provinceName = "测试省份";
    	//城市
    	String cityName = "测试城市";
    	//地区
    	String areaName = "测试地区";
    	//地址
    	String address = "测试地址";
    	//创建者,必填
    	Long creatorId = 2L;
    	//归属者
    	Long ownerId = 3L;
    	//客户类型,必填
    	String typeName = "测试类型";
    	//客户来源,必填
    	String sourceName = "测试来源";
    	//公司
    	String companyName = "测试公司";
    	
    	//扩展字段
    	Map<String, Object> extColumns = new HashMap<>();
    	extColumns.put("qqd_customer_zhiwei", "扩展字段");
    	
        viewCustomer.setPhoneNumber(phoneNumber);
        viewCustomer.setEmail(email);
        viewCustomer.setName(name);
        viewCustomer.setSex(sex);
        viewCustomer.setBirthdayStr(birthdayStr);
        viewCustomer.setCountryName(countryName);
        viewCustomer.setProvinceName(provinceName);
        viewCustomer.setCityName(cityName);
        viewCustomer.setAreaName(areaName);
        viewCustomer.setAddress(address);
        viewCustomer.setCreatorId(creatorId);
        viewCustomer.setOwnerId(ownerId);
        viewCustomer.setTypeName(typeName);
        viewCustomer.setSourceName(sourceName);
        viewCustomer.setCompanyName(companyName);
        viewCustomer.setExtColumns(extColumns);
        viewCustomerList.add(viewCustomer);
    	ImportCustomerResponse importCustomerResponse = gsccServer.importCustomerCommand(viewCustomerList,overWriteData);
        System.out.println(importCustomerResponse.toJsonString());
        
        //批量导入客户批次
    	List<CustomerBatch> customerBatchList = new ArrayList<>();
    	CustomerBatch importCustomerBatch = new CustomerBatch();
    	//必填，是否允许删除
    	Boolean canDelete = false;
    	importCustomerBatch.setCanDelete(canDelete);
    	//不必填写，系统自动创建，创建时间
//    	Date createDate = new Date();
//    	customerBatch.setCreateDate(createDate);
    	//必填，创建者编号
    	Long creatorId1 = 1L;
    	importCustomerBatch.setCreatorId(creatorId1);
    	//选填，批次描述
    	String description = "API接口导入"+System.currentTimeMillis();
    	importCustomerBatch.setDescription(description);
    	//不必填写，系统自动创建，批次编号
//    	Long id = 5L;
//    	customerBatch.setId(id);
    	//必填，批次名称
    	String name1 = "批次名称导入"+System.currentTimeMillis();
    	importCustomerBatch.setName(name1);
    	//必填，归属人编号
    	Long ownerId1 = 2L;
    	importCustomerBatch.setOwnerId(ownerId1);
    	//不必填写，系统自动创建，批次状态 NORMAL(0,"正常"),ERROR(1,"异常"),PROCESSING(2,"正在处理"),DELETING(3,"正在删除"),
//    	Integer state = 1;
//    	customerBatch.setState(state);
    	customerBatchList.add(importCustomerBatch);
    	ImportCustomerBatchResponse importCustomerBatchResponse = gsccServer.importCustomerBatchCommand(customerBatchList);
    	System.out.println(importCustomerBatchResponse.toJsonString());
    	
    	//绑定客户和批次编号
    	//客户编号
    	List<Long> customerIdList = new ArrayList<>(); 
    	customerIdList.add(1L);
    	customerIdList.add(2L);
    	CustomerBatch customerBatch = new CustomerBatch();
    	//必填，是否允许删除
    	Boolean canDelete1 = false;
    	customerBatch.setCanDelete(canDelete1);
    	//不必填写，系统自动创建，创建时间
//    	Date createDate = new Date();
//    	customerBatch.setCreateDate(createDate);
    	//必填，创建者编号
    	Long creatorId11 = 1L;
    	customerBatch.setCreatorId(creatorId11);
    	//选填，批次描述
    	String description1 = "API接口导入"+System.currentTimeMillis();
    	customerBatch.setDescription(description1);
    	//必填，批次名称
    	String name11 = "批次名称导入"+System.currentTimeMillis();
    	customerBatch.setName(name11);
    	//必填，归属人编号
    	Long ownerId11 = 2L;
    	customerBatch.setOwnerId(ownerId11);
    	//不必填写，系统自动创建，批次状态 NORMAL(0,"正常"),ERROR(1,"异常"),PROCESSING(2,"正在处理"),DELETING(3,"正在删除"),
//    	Integer state = 1;
//    	customerBatch.setState(state);
    	
    	Boolean isNewBatch = true;
    	//isNewBatch=true不必填写，系统自动创建，isNewBatch=false只需要指定批次编号即可
//    	Long id = 3L;
//    	customerBatch.setId(id);
    	
    	BindCustomerBatchLinkResponse bindCustomerBatchLinkResponse = gsccServer.bindCustomerBatchLinkCommand(customerIdList, customerBatch, isNewBatch);
    	System.out.println(bindCustomerBatchLinkResponse.toJsonString());
        
    }

}
